package com.marchsoft.musicalstore.controller;

import com.marchsoft.musicalstore.entity.Instrument;
import com.marchsoft.musicalstore.service.InstrumentSer;
import com.marchsoft.musicalstore.util.RequestToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 源
 * Date: 2019-11-21
 * Time: 21:17
 */
@RestController
@RequestMapping("instrument")
public class InstrumentCon {

    @Autowired
    InstrumentSer instrumentSer;

    /**
     * 0代表此商品还在售卖
     * @param type
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping(value = "/getInstr",method = RequestMethod.GET)
    public RequestToJson getInstruByTypeLimit(Integer type, Integer page, Integer limit){
        List<Instrument> instruByTypeLimit = instrumentSer.getInstruByTypeLimit(type, page, limit);
        RequestToJson res = new RequestToJson(0, "成功", instruByTypeLimit);
        return res;
    }

    /**
     * 可能是点击商品的分页面，原型图不是十分明确
     * @param id
     * @return
     */
    @RequestMapping(value = "/getInstruById",method = RequestMethod.GET)
    public RequestToJson getInstruById(Integer id){
        Optional<Instrument> instruById = instrumentSer.getInstruById(id);
        RequestToJson res = new RequestToJson(0, "成功", instruById);
        return res;
    }

}
